package com.soulless.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * <p>
 *
 * </p>
 *
 * @author zenglei
 * @date 2022/04/22/ 19:24
 */
public class AnnotationTest {

    public static void main(String[] args) throws ClassNotFoundException {
        parse("com.soulless.annotation.AnnoObj");
    }

    public static void parse(String className) throws ClassNotFoundException {
        Class<?> cls = Class.forName(className);
        Anno anno = cls.getAnnotation(Anno.class);
        System.out.println("anno   " + anno);
        if (null != anno) {
            String name = anno.name();
            System.out.println(name);
        } else {
            System.out.println("没有注解");
        }
    }

}

//@Anno(name = "测试")
class AnnoObj {}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface Anno {

    String name() default "";

}
